package com.tablepet.utils;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import java.util.List;
public class Utils {
    public static boolean isActive(Intent intent,Context context){
        @SuppressLint("QueryPermissionsNeeded") ComponentName cmpName = intent.resolveActivity(context.getPackageManager());
        if (cmpName != null) {
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(10);
            for (ActivityManager.RunningTaskInfo runningTask : runningTasks) {
                if (runningTask.baseActivity.equals(cmpName)) {
                    return true;
                }
            }
        }
        return false;
    }
    public static void backToDesktop(Context context){
        context.startActivity(new Intent(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).addCategory(Intent.CATEGORY_HOME));
    }
}
